package bzimerman.media.myflix;

import java.io.File;
import java.util.Arrays;

import org.apache.commons.io.comparator.LastModifiedFileComparator;
import org.apache.commons.io.comparator.NameFileComparator;
import org.apache.commons.io.comparator.PathFileComparator;
import org.apache.commons.io.comparator.SizeFileComparator;

public class sorterHelper {
	private enum SORTMODE{ NAME, TYPE, MODIFIED, SIZE; }
	public SORTMODE sortMode;
	public sorterHelper(){
		sortMode = SORTMODE.NAME;
	}
	public void setSorter(int number){
		switch(number){
			case 0: sortMode = SORTMODE.NAME; break;
			case 1: sortMode = SORTMODE.TYPE; break;
			case 2: sortMode = SORTMODE.MODIFIED; break;
			case 3: sortMode = SORTMODE.SIZE; break;
		}
	}
	public int getSorter(){
		switch(sortMode){
			case NAME: return 0;
			case TYPE: return 1;
			case MODIFIED: return 2;
			case SIZE: return 3;
			default: return 0;
		}
	}
	public File[] fileSort(File[] files){
    	if(files!=null){
    		switch(sortMode){
    			case NAME:
    				Arrays.sort(files, NameFileComparator.NAME_COMPARATOR);
    				break;
    			case TYPE:
    				Arrays.sort(files, PathFileComparator.PATH_SYSTEM_COMPARATOR);
    				break;
    			case MODIFIED:
    				Arrays.sort(files, LastModifiedFileComparator.LASTMODIFIED_REVERSE);
    				break;
    			case SIZE:
    				Arrays.sort(files, SizeFileComparator.SIZE_REVERSE);
    				break;
    			default: break;
    		}
    	}
    	return files;
    }
}
